package com.controller;

import com.model.Orders;
import com.page.GenericPage;
import com.po.DeviceBoxPO;
import com.po.OrdersPO;
import com.result.Result;
import com.service.DeviceBoxService;
import com.service.OrdersService;
import com.vo.DeviceBoxVO;
import com.vo.OrderCondition;
import com.vo.OrdersQueryVO;
import com.vo.OrdersVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 14:08
 * @Version 1.0
 * @Note
 */
@Api(value = "ordersApi")
@CrossOrigin
@RestController
@RequestMapping("/orders")
public class OrdersController {


    @Autowired
    private OrdersService ordersService;

    @ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<OrdersVO> save(@RequestBody OrdersPO ordersPO) {
        return new Result<OrdersVO>().ok(ordersService.save(ordersPO));
    }

    @ApiOperation(value = "获取订单", httpMethod = "GET", notes = "获取订单")
    @RequestMapping(value = "/selectByOrderNumber", method = RequestMethod.GET)
    public Result<Orders> selectByOrderNumber(@RequestParam("orderNumber") String orderNumber) {
        return ordersService.selectByOrderNumber(orderNumber);
    }

    @ApiOperation(value = "分页查询订单列表", httpMethod = "POST", notes = "分页查询订单列表")
    @RequestMapping(value = "/queryOrderPage", method = RequestMethod.POST)
    public Result<GenericPage<OrdersQueryVO>> queryAccountPage(@RequestBody OrderCondition condition) {
       return ordersService.findOrderByPage(condition);
    }


    @ApiOperation(value = "获取订单", httpMethod = "GET", notes = "获取订单")
    @RequestMapping(value = "/updateLockStatus", method = RequestMethod.GET)
    public Result<Boolean> updateLockStatus(@RequestParam("orderId") Long orderId, @RequestParam("lockStatus") Integer lockStatus) {
        return ordersService.updateLockStatus(orderId,lockStatus);
    }
}
